# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: cron_clear.py
@time: 2024/11/3 20:58 
@desc: 定时任务

"""
import os
import time
from scripts.base_script import BaseScript
from config import TASKS_TIMEOUT


class Solution(BaseScript):
    """

    """

    def __init__(self):
        super(Solution, self).__init__()
        self.desc = f"定时任务"
        print(self.desc)

    def check_exists_times(self, file, seconds):
        """

        :param file:
        :param seconds:
        :return:
        """
        current_time = time.time()
        file_mod_time = os.path.getmtime(file)

        file_age = current_time - file_mod_time

        if file_age > seconds:
            return True
        return False

    def process(self):
        """

        :return:
        """
        base_path = "/home/jiaohaicheng/celery_test"
        # base_path = r"C:\Users\JHC\Desktop\dest\celery_test"
        for folder in [self.folder.merge_path([base_path, "tmp"]),
                       self.folder.merge_path([base_path, "static", "download"])]:
            for file in self.get_file(folder):
                if self.check_exists_times(file, TASKS_TIMEOUT):
                    self.file.remove(file=file)


if __name__ == '__main__':
    s = Solution()
    s.process()
